package com.liuyz;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class InetAddress_ {

    public static void main(String[] args) throws UnknownHostException {
        InetAddress inetAddress = InetAddress.getLocalHost(); // 获取本机InetAddress对象
        System.out.println(inetAddress); // 直接输出格式：主机名/ip
        InetAddress inetAddress1 = InetAddress.getByName("wwww.baidu.com"); // 根据域名获取InetAddress对象
        System.out.println(inetAddress1);
        InetAddress inetAddress2 = InetAddress.getByName("5CQJEN5"); // 根据主机名获取InetAddress对象
        System.out.println(inetAddress2);
        System.out.println(inetAddress1.getHostName()); // 获取主机名/域名
        System.out.println(inetAddress1.getHostAddress()); // 获取ip
    }

}
